package com.onec.service.customer.entity.merchant;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.onec.service.api.content.AesEntityContent;
import com.onec.service.api.enums.ProductEnum;
import com.onec.service.api.enums.StatusEnum;
import lombok.Data;
import org.hibernate.annotations.ColumnTransformer;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 代理商
 * 渠道信息。
 *
 * @author ONEC
 */
@Data
@Entity
@Table(name = "t_merchant_account")
public class MerchantAccount implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true)
    private Long id;

    @Column(name = "version", length = 8)
    @Version
    private Integer version;

    @Column(name = "merchant_id", length = 16)
    private Long merchantId;

    /**
     * 具体的产品业务：
     */
    @Column(name = "business_no", length = 16)
    private String businessNo;
    /**
     * 通道编号
     */
    @Column(name = "total_amount", length = 8, scale = 2)
    private BigDecimal totalAmount;
    /**
     * 通道名称
     */
    @Column(name = "freeze_amount", length = 8, scale = 2)
    private BigDecimal freezeAmount;

    /**
     * 联系人
     */
    @Column(name = "use_amount", length = 8, scale = 2)
    private BigDecimal useAmount;


    @Column(name = "product", length = 8)
    @Enumerated(value = EnumType.STRING)
    private ProductEnum product;

    /**
     * 联系人
     */
    @Column(name = "contacts", length = 32)
    private String contacts;

    /**
     * 机构编号
     */
    @Column(name = "phone")
    @ColumnTransformer(
            read = AesEntityContent.AES_DECRYPT_PHONE,
            write = AesEntityContent.AES_ENCRYPT_PHONE
    )
    private String phone;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date createTime;
    /**
     * 变更
     */
    @Column(name = "update_time")
    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date updateTime;
    /**
     * 创建者
     */
    @Column(name = "creator", length = 32)
    private String creator;
    /**
     * 产品备注
     */
    @Column(name = "remarks", length = 64)
    private String remarks;
    /**
     * 通道状态
     */
    @Column(name = "status", length = 12)
    @Enumerated(value = EnumType.STRING)
    private StatusEnum status;

}
